package org.jdesktop.swingx.table.model;

import javax.swing.table.TableModel;

public abstract class AbstractAddColumnTableModelWapper extends AbstractTableModelWapper<TableModel> {

	protected int befColumnNumber;
	
	public AbstractAddColumnTableModelWapper(TableModel t,int befColumnNumber) {
		super(t);
		this.befColumnNumber=befColumnNumber;
	}
	
	public abstract Object getColumnValue(int rowIndex);
	
	public abstract String getColumnName();
	
	public abstract Class getColumnClass();

	@Override
	public int getColumnCount() {
		return super.getColumnCount()+1;
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		if(columnIndex==befColumnNumber)
			return getColumnValue(rowIndex);
		return super.getValueAt(rowIndex, columnIndex);
	}

	@Override
	public String getColumnName(int columnIndex) {
		if(columnIndex==befColumnNumber)
			return getColumnName();
		return super.getColumnName(columnIndex);
	}

	@Override
	public Class<?> getColumnClass(int columnIndex) {
		if(columnIndex==befColumnNumber)
			return getColumnClass();
		return super.getColumnClass(columnIndex);
	}

	@Override
	public boolean isCellEditable(int rowIndex, int columnIndex) {
		if(columnIndex==befColumnNumber)
			return false;
		return super.isCellEditable(rowIndex, columnIndex);
	}

	@Override
	public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
		if(columnIndex==befColumnNumber)
			return ;
		super.setValueAt(aValue, rowIndex, columnIndex);
	}
	
	@Override
	public int getColumnIndex(int wapperColumnIndex) {
		if(wapperColumnIndex>befColumnNumber)
			wapperColumnIndex--;
		 return wapperColumnIndex;
	}

	@Override
	public int getRowIndex(int wapperRowIndex) {
		return wapperRowIndex;
	}
	
	
	@Override
	public int getRealColumnNumber(int wapperColumnNumber) {
		if(wapperColumnNumber==befColumnNumber)
			return -1;
		else if(wapperColumnNumber>befColumnNumber)
			wapperColumnNumber--;
		return super.getRealColumnNumber(wapperColumnNumber);
	}
}
